<template>
	<view class="body">
		<u-navbar title="会员专区" back-icon-color="#000" title-color="#000" :border-bottom="false" custom-class="home-bg" :background="{ background: 'transparent' }"></u-navbar>

		<view class="top-image">
			<image src="/static/user/vip.png" style="width: 686rpx; height: 196rpx"></image>
		</view>

		<view style="margin: 0 30rpx">
			<view v-for="(item, index) in hotVips">
				<view class="hotGoods">
					<view style="display: flex">
						<image class="img-axGood" :src="path + item.img" mode="aspectFill"></image>
						<view class="right">
							<view>
								<view class="flex">
									<text class="right-top">{{ item.memberName }}</text>
								</view>
								<view class="text-vip">
									<view class="flex align-center">
										收益比例-
										<text>{{ item.incomeRate }}</text>
									</view>
									<view class="flex align-center">
										别名-
										<text>{{ item.cardAlias }}</text>
									</view>
								</view>
							</view>
							<view class="right-bottom">
								<text>
									<span>￥</span>
									{{ item.cardPrice }}
								</text>
							</view>
						</view>
					</view>
					<button @click="buy(item.id)">购买</button>

					<view class="vip-detail" @click="vipTap(index)">
						<text style="margin-right: 10rpx">点击展开查看详情</text>
						<u-icon v-if="isDetail == index" name="arrow-down"></u-icon>
						<u-icon v-else name="arrow-up"></u-icon>
					</view>
				</view>
				<view v-if="isDetail == index">
					<rich-text :nodes="item.cardDetail"></rich-text>
				</view>
			</view>
		</view>

		<u-modal v-model="show" @confirm="addTap()" content="确定要购买该Vip礼包吗?" :mask-close-able="true" :show-title="false" :show-cancel-button="true"></u-modal>
	</view>
</template>

<script>
import api from '@/api/index.js';
import oerder from '@/api/oerder';
export default {
	data() {
		return {
			show: false,
			hotVips: [],
			path: api.getPath(),
			isDetail: -1,
			id: 0
		};
	},
	onLoad(o) {
		this.getVipList();
	},
	methods: {
		getVipList() {
			oerder.getVip({}).then((res) => {
				this.hotVips = res.rows;
			});
		},
		buy(id) {
			this.show = true;
			this.id = id;
		},
		addTap() {
			oerder
				.buyVip({
					goodId: this.id,
					moneyType: 1
				})
				.then((res) => {
					uni.showToast({
						title: '成功购买该会员礼包',
						icon: 'success'
					});
				});
		},
		vipTap(index) {
			if (this.isDetail == index) {
				this.isDetail = -1;
			} else {
				this.isDetail = index;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.vip-detail {
	position: absolute;
	right: 0;
	bottom: 0;
	font-size: 20rpx;
}
.body {
	width: 750rpx;
	height: 430rpx;
	background: linear-gradient(180deg, #ffddb8 0%, #f5f5f5 100%);
}
.top-image {
	margin-top: 30rpx;
	margin-bottom: 50rpx;
	display: flex;
	justify-content: center;
}
.text-vip {
	font-size: 25rpx;
	text {
		color: red;
	}
}
.hotGoods {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 20rpx 0 35rpx 0;
	position: relative;
	.img-axGood {
		width: 240rpx;
		height: 149.29rpx;
		border-radius: 15rpx 15rpx 15rpx 15rpx;
		margin-right: 20rpx;
	}
	.right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin: 5rpx 0;
		.right-top {
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			width: 250rpx;

			display: -webkit-box;
			-webkit-line-clamp: 1; /* 限制为两行 */
			-webkit-box-orient: vertical;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.right-bottom {
			display: flex;
			align-items: center;
			text {
				font-family: MiSans, MiSans;
				font-weight: 500;
				font-size: 30rpx;
				color: #f05a39;
				text-align: center;
				font-style: normal;
				text-transform: none;
				span {
					font-size: 23rpx;
				}
			}
			.right-time {
				position: absolute;
				left: 420rpx;
				margin-left: 15rpx;
				padding-right: 20rpx;
				width: 150rpx;
				height: 35rpx;
				background: url('@/static/main/time.png') no-repeat;
				background-size: 144.71rpx 34rpx;
				display: flex;
				align-items: center;
				justify-content: end;
			}
		}
	}

	button {
		width: 110rpx;
		height: 62rpx;
		background: linear-gradient(269deg, #f26f43 0%, #f34836 100%);
		border-radius: 166rpx 166rpx 166rpx 166rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #ffffff;
	}
}
</style>
